import { ref, reactive } from 'vue';
import { hQueryToken, hQueryList, hQueryCollectList, hQueryCollectAdd } from '/@/api/linkoo/form';
export default function () {
	//配置默认 密码
	const hPassword = ref('123456');
	//配置默认坐标 120.10147,29.318379
	const hMapConf=reactive({
      lonlat:'120.10147,29.318379',
	  lon:'120.10147',
	  lat:'29.318379',
	  addr:'江滨北路281号义乌市政府行政二号楼义乌市数字城市管理中心'
	})
	let userInfo = ref();
	const hGetLoadToken = (hStore) => {
		userInfo = hStore.state.userInfos.userInfos;
		loadToken();
	};

	const loadToken = () => {
		let username = userInfo.userName;
		hQueryToken(username, hPassword.value).then((res) => {
			console.log(' 获取token', res);
			if (res.data.token) {
				userInfo['hToken'] = res.data.token;
			}
		});
	};
	const hGetToken = () => {
		return userInfo['hToken'];
	};
	const hGUserInfo = () => {
		return userInfo;
	};
	const hCollectAdd = (token, collectClass) => {
		return hQueryCollectAdd(token, collectClass);
	};
	const hGetId = (len, radix) => {
		var chars = '0123456789abcdefhigklmnopqrstuvwxyz'.split('');
		var uuid = [],
			i;
		radix = radix || chars.length;
		if (len) {
			for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
		} else {
			var r;
			uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
			uuid[14] = '4';
			for (i = 0; i < 36; i++) {
				if (!uuid[i]) {
					r = 0 | (Math.random() * 16);
					uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
				}
			}
		}

		return uuid.join('');
	};

	return {
		hGetLoadToken,
		hGetToken,
		hGUserInfo,
		hCollectAdd,
        hGetId,
		hMapConf
	};
}
